﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LuaFramework;
using LuaInterface;
using UnityEngine.EventSystems;

namespace LuaFramework {
	/// <summary>
	/// 用于UGUI动画
	/// </summary>
	public class LuaUGUIComponent : LuaComponent,IPointerUpHandler,IPointerDownHandler,IPointerEnterHandler,IPointerClickHandler {

		public void OnPointerUp(PointerEventData eventData)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnPointerUp");
				if (func != null)
				{
					func.Call(_table,eventData);
					func.Dispose();
					func = null;
				}
			}
		}

		public void OnPointerDown(PointerEventData eventData)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnPointerDown");
				if (func != null)
				{
					func.Call(_table,eventData);
					func.Dispose();
					func = null;
				}
			}
		}

		public void OnPointerEnter(PointerEventData eventData)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnPointerEnter");
				if (func != null)
				{
					func.Call(_table,eventData);
					func.Dispose();
					func = null;
				}
			}
		}

		public void OnPointerExit(PointerEventData eventData)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnPointerExit");
				if (func != null)
				{
					func.Call(_table,eventData);
					func.Dispose();
					func = null;
				}
			}
		}

		public void OnPointerClick(PointerEventData eventData)
		{
			if (!string.IsNullOrEmpty(_name))
			{
				if (!LuaManager.IsInited || _table==null) return;

				LuaFunction func = _table.GetLuaFunction("OnPointerClick");
				if (func != null)
				{
					func.Call(_table,eventData);
					func.Dispose();
					func = null;
				}
			}
		}
    }
}